package com.xgk.boot.module.core.service.truck;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.cache.Cache;
import com.mzt.logapi.context.LogRecordContext;
import com.mzt.logapi.starter.annotation.LogRecord;
import com.xgk.boot.framework.common.constant.ErrorCodeConstants;
import com.xgk.boot.framework.common.exception.util.ServiceExceptionUtil;
import com.xgk.boot.framework.common.pojo.PageResult;
import com.xgk.boot.framework.common.util.cache.CacheUtils;
import com.xgk.boot.framework.common.util.object.BeanUtils;
import com.xgk.boot.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.xgk.boot.framework.redis.core.RedisLockManager;
import com.xgk.boot.framework.security.core.util.SecurityFrameworkUtils;
import com.xgk.boot.module.core.controller.admin.account.vo.OrderNumVo;
import com.xgk.boot.module.core.controller.admin.account.vo.OrderStatVO;
import com.xgk.boot.module.core.controller.admin.truck.vo.*;
import com.xgk.boot.module.core.dal.dto.TruckOrderDto;
import com.xgk.boot.module.core.dal.entity.truck.TruckOrderAddressDO;
import com.xgk.boot.module.core.dal.entity.truck.TruckOrderCancelLogDO;
import com.xgk.boot.module.core.dal.entity.truck.TruckOrdersDO;
import com.xgk.boot.module.core.dal.iservice.truck.TruckOrdersService;
import com.xgk.boot.module.core.dal.mapper.truck.TruckOrdersMapper;
import com.xgk.boot.module.core.dal.redis.RedisLockConstants;
import com.xgk.boot.module.core.enums.biz.AddressTypeEnum;
import com.xgk.boot.module.core.enums.biz.ApprovalTypeEnum;
import com.xgk.boot.module.core.enums.biz.OrderStatusEnum;
import com.xgk.boot.module.core.service.permission.UserRoleServiceImpl;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.Duration;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.stream.Collectors;

import static com.xgk.boot.module.core.enums.LogRecordConstants.*;

/**
 * 卡车订单主表 服务实现
 */
@Slf4j
@Service
public class TruckOrdersServiceImpl extends ServiceImpl<TruckOrdersMapper, TruckOrdersDO> implements TruckOrdersService {

    //订单编码生成： CommonUtil.getNewOrderCode();

    private static Cache<String,String> orderPermissionCache =  CacheUtils.buildCache(Duration.ofHours(3));

    @Resource
    private TruckOrderAddressServiceImpl truckOrderAddressService;
    @Resource
    private TruckOrderCancelLogServiceImpl truckOrderCancelLogService;
    @Resource
    private TruckOrderLogServiceImpl  truckOrderLogService;
    @Resource
    private UserRoleServiceImpl userRoleService;
    @Resource
    private TruckOrderFeeDetailServiceImpl orderFeeDetailService;

    @Resource
    private RedisLockManager lockManager;

    /**
     * 分页查看订单
     * @param orderReqVO
     * @return
     */
    public PageResult<TruckOrderVO> pageTruckOrders(TruckOrderReqVO orderReqVO){
        if(orderReqVO == null){
            return new PageResult<>();
        }
        LambdaQueryWrapperX<TruckOrdersDO> ordersWrapperX = new LambdaQueryWrapperX<>();
        ordersWrapperX.eqIfPresent(TruckOrdersDO::getCustomerCode, orderReqVO.getCustomerCode());
        if(StrUtil.isNotBlank(orderReqVO.getOrderCode())){
            List<String> strList = getStrList(orderReqVO.getOrderCode());
            if(strList.size()>1){
                ordersWrapperX.in(TruckOrdersDO::getOrderCode, strList);
            }else {
                ordersWrapperX.eq(TruckOrdersDO::getOrderCode, strList.get(0));
            }
        }
        if(StrUtil.isNotBlank(orderReqVO.getReferenceNo())){
            List<String> strList = getStrList(orderReqVO.getReferenceNo());
            if(strList.size()>1){
                ordersWrapperX.in(TruckOrdersDO::getReferenceNo, strList);
            }else {
                ordersWrapperX.eq(TruckOrdersDO::getReferenceNo, strList.get(0));
            }
        }
        if(StrUtil.isNotBlank(orderReqVO.getTrackingNumber())){
            List<String> strList = getStrList(orderReqVO.getTrackingNumber());
            if(strList.size()>1){
                ordersWrapperX.in(TruckOrdersDO::getTrackingNumber, strList);
            }else {
                ordersWrapperX.eq(TruckOrdersDO::getTrackingNumber, strList.get(0));
            }
        }
        ordersWrapperX.eqIfPresent(TruckOrdersDO::getProductCode, orderReqVO.getProductCode())
                .eqIfPresent(TruckOrdersDO::getOrderStatus, orderReqVO.getOrderStatus())
                .eqIfPresent(TruckOrdersDO::getSpCode, orderReqVO.getSpCode())
                .betweenIfPresent(TruckOrdersDO::getCreateTime, orderReqVO.getBeginCreateTime(), orderReqVO.getEndCreateTime());
        ordersWrapperX.orderByDesc(TruckOrdersDO::getCreateTime);

        ordersWrapperX.select(
                TruckOrdersDO::getOrderId,
                TruckOrdersDO::getOrderCode,
                TruckOrdersDO::getCustomerCode,
                TruckOrdersDO::getProductCode,
                TruckOrdersDO::getSpCode,
                TruckOrdersDO::getOrderStatus,
                TruckOrdersDO::getCurrencyCode,
                TruckOrdersDO::getTrackingNumber,
                TruckOrdersDO::getShippingFeeEstimate,
                TruckOrdersDO::getReferenceNo,
                TruckOrdersDO::getCreateTime,
                TruckOrdersDO::getUpdateTime);
        Page<TruckOrdersDO> page=new Page<>(orderReqVO.getCurrent(),orderReqVO.getPageSize());
        Page<TruckOrdersDO> pageRes = this.page(page, ordersWrapperX);

        if(pageRes == null || CollUtil.isEmpty(pageRes.getRecords())){
            return new PageResult<>();
        }
        Map<String, TruckOrderAddressDO> orderPostCode = getOrderPostCode(pageRes.getRecords());
        List<TruckOrderVO> truckOrderVOS = BeanUtils.toBean(pageRes.getRecords(), TruckOrderVO.class);
        for (TruckOrderVO truckOrderVO : truckOrderVOS) {
            TruckOrderAddressDO addressDO = orderPostCode.get(truckOrderVO.getOrderCode() + "_0");
            if(addressDO != null){
                truckOrderVO.setPickUpCountry(addressDO.getOaCountry());
                truckOrderVO.setPickUpPostcode(addressDO.getOaPostcode());
            }
            TruckOrderAddressDO addressDO2 = orderPostCode.get(truckOrderVO.getOrderCode() + "_1");
            if(addressDO2 != null){
                truckOrderVO.setDeliveryCountry(addressDO2.getOaCountry());
                truckOrderVO.setDeliveryPostCode(addressDO2.getOaPostcode());
            }
        }
        return new PageResult<>(truckOrderVOS, pageRes.getTotal(), orderReqVO.getCurrent(), orderReqVO.getPageSize());
    }


    /**
     * 分页查看订单
     * @param orderReqVO
     * @return
     */
    public PageResult<TruckOrderVO> pageCancelTruckOrders(TruckOrderReqVO orderReqVO){
        if(orderReqVO == null){
            return new PageResult<>();
        }
        LambdaQueryWrapperX<TruckOrdersDO> ordersWrapperX = new LambdaQueryWrapperX<>();
        ordersWrapperX.eqIfPresent(TruckOrdersDO::getCustomerCode, orderReqVO.getCustomerCode());
        if(StrUtil.isNotBlank(orderReqVO.getOrderCode())){
            List<String> strList = getStrList(orderReqVO.getOrderCode());
            if(strList.size()>1){
                ordersWrapperX.in(TruckOrdersDO::getOrderCode, strList);
            }else {
                ordersWrapperX.eq(TruckOrdersDO::getOrderCode, strList.get(0));
            }
        }
        if(StrUtil.isNotBlank(orderReqVO.getReferenceNo())){
            List<String> strList = getStrList(orderReqVO.getReferenceNo());
            if(strList.size()>1){
                ordersWrapperX.in(TruckOrdersDO::getReferenceNo, strList);
            }else {
                ordersWrapperX.eq(TruckOrdersDO::getReferenceNo, strList.get(0));
            }
        }
        if(StrUtil.isNotBlank(orderReqVO.getTrackingNumber())){
            List<String> strList = getStrList(orderReqVO.getTrackingNumber());
            if(strList.size()>1){
                ordersWrapperX.in(TruckOrdersDO::getTrackingNumber, strList);
            }else {
                ordersWrapperX.eq(TruckOrdersDO::getTrackingNumber, strList.get(0));
            }
        }
        ordersWrapperX.eqIfPresent(TruckOrdersDO::getProductCode, orderReqVO.getProductCode())
                .eqIfPresent(TruckOrdersDO::getOrderStatus, orderReqVO.getOrderStatus())
                .eqIfPresent(TruckOrdersDO::getSpCode, orderReqVO.getSpCode())
                .betweenIfPresent(TruckOrdersDO::getCreateTime, orderReqVO.getBeginCreateTime(), orderReqVO.getEndCreateTime());
        ordersWrapperX.orderByDesc(TruckOrdersDO::getCreateTime);

        ordersWrapperX.select(
                TruckOrdersDO::getOrderId,
                TruckOrdersDO::getOrderCode,
                TruckOrdersDO::getCustomerCode,
                TruckOrdersDO::getProductCode,
                TruckOrdersDO::getSpCode,
                TruckOrdersDO::getOrderStatus,
                TruckOrdersDO::getCurrencyCode,
                TruckOrdersDO::getTrackingNumber,
                TruckOrdersDO::getShippingFeeEstimate,
                TruckOrdersDO::getReferenceNo,
                TruckOrdersDO::getCreateTime,
                TruckOrdersDO::getUpdateTime);
        Page<TruckOrdersDO> page=new Page<>(orderReqVO.getCurrent(),orderReqVO.getPageSize());
        Page<TruckOrdersDO> pageRes = this.page(page, ordersWrapperX);

        if(pageRes == null || CollUtil.isEmpty(pageRes.getRecords())){
            return new PageResult<>();
        }
        Map<String, TruckOrderAddressDO> orderPostCode = getOrderPostCode(pageRes.getRecords());
        List<TruckOrderVO> truckOrderVOS = BeanUtils.toBean(pageRes.getRecords(), TruckOrderVO.class);
        for (TruckOrderVO truckOrderVO : truckOrderVOS) {
            TruckOrderAddressDO addressDO = orderPostCode.get(truckOrderVO.getOrderCode() + "_0");
            if(addressDO != null){
                truckOrderVO.setPickUpCountry(addressDO.getOaCountry());
                truckOrderVO.setPickUpPostcode(addressDO.getOaPostcode());
            }
            TruckOrderAddressDO addressDO2 = orderPostCode.get(truckOrderVO.getOrderCode() + "_1");
            if(addressDO2 != null){
                truckOrderVO.setDeliveryCountry(addressDO2.getOaCountry());
                truckOrderVO.setDeliveryPostCode(addressDO2.getOaPostcode());
            }
        }
        return new PageResult<>(truckOrderVOS, pageRes.getTotal(), orderReqVO.getCurrent(), orderReqVO.getPageSize());
    }

    public Map<String,TruckOrderAddressDO> getOrderPostCode(List<TruckOrdersDO> list){
        LambdaQueryWrapperX<TruckOrderAddressDO> addressWrapper = new LambdaQueryWrapperX<>();
        List<String> collect = list.stream().map(TruckOrdersDO::getOrderCode).collect(Collectors.toList());
        addressWrapper.in(TruckOrderAddressDO::getOrderCode, collect)
                .select(TruckOrderAddressDO::getOrderCode,
                        TruckOrderAddressDO::getOaCountry,
                        TruckOrderAddressDO::getOaType,
                        TruckOrderAddressDO::getOaPostcode);
        List<TruckOrderAddressDO> addressDOList = truckOrderAddressService.list(addressWrapper);
        if(addressDOList == null || addressDOList.isEmpty()){
            return Collections.emptyMap();
        }
        Map<String,TruckOrderAddressDO> map =new HashMap<>();
        for (TruckOrderAddressDO addressDO : addressDOList) {
            map.put(addressDO.getOrderCode()+"_"+addressDO.getOaType(), addressDO);
        }
        return map;
    }


    public Boolean checkOrderPermission(String orderCode) {
        String ifPresent = orderPermissionCache.getIfPresent(orderCode);
        if(StrUtil.isNotBlank(ifPresent)){
            return ifPresent.equals(SecurityFrameworkUtils.getLoginUserName());
        }

        LambdaQueryWrapperX<TruckOrdersDO> ordersWrapperX = new LambdaQueryWrapperX<>();
        ordersWrapperX.eq(TruckOrdersDO::getOrderCode, orderCode)
                .select(TruckOrdersDO::getCustomerCode);
        TruckOrdersDO order = this.getOne(ordersWrapperX);
        if(order == null){
            return false;
        }
        orderPermissionCache.put(orderCode, order.getCustomerCode());
        // 检查订单是否属于该客户
        return order.getCustomerCode().equals(SecurityFrameworkUtils.getLoginUserName());
    }

    private List<String> getStrList(String str){
        return Arrays.stream(str.split("[,;]"))
                .map(String::trim) // 可选：去除前后空格
                .filter(s -> !s.isEmpty()) // 可选：过滤空字符串
                .collect(Collectors.toList());
    }

    public TruckOrderBaseVO getTruckOrderBaseVO(String orderCode) {
        LambdaQueryWrapperX<TruckOrdersDO> ordersWrapperX = new LambdaQueryWrapperX<>();
        ordersWrapperX.eq(TruckOrdersDO::getOrderCode, orderCode);
        TruckOrdersDO order = this.getOne(ordersWrapperX);
        if(order == null){
            return null;
        }
        List<TruckOrderAddressDO> orderAddress = truckOrderAddressService.list(
                new LambdaQueryWrapperX<TruckOrderAddressDO>()
                        .eq(TruckOrderAddressDO::getOrderCode, orderCode));
        TruckOrderBaseVO truckOrderBaseVO = new TruckOrderBaseVO();
        truckOrderBaseVO.setOrder(BeanUtils.toBean(order, TruckOrderVO.class));
        if(CollectionUtils.isNotEmpty(orderAddress)){
            orderAddress.forEach(addressDO -> {
                if(addressDO.getOaType().equals(AddressTypeEnum.PICKUP.getValue())){
                    truckOrderBaseVO.setPickupAddress(BeanUtils.toBean(addressDO, OrderAddressVO.class));
                }else{
                    truckOrderBaseVO.setDeliveryAddress(BeanUtils.toBean(addressDO, OrderAddressVO.class));
                }
            });
        }
        return truckOrderBaseVO;
    }

    public TruckOrdersDO getTruckOrderByCode(String orderCode) {
        LambdaQueryWrapperX<TruckOrdersDO> ordersWrapperX = new LambdaQueryWrapperX<>();
        ordersWrapperX.eq(TruckOrdersDO::getOrderCode, orderCode);
        TruckOrdersDO order = this.getOne(ordersWrapperX);
        if(order == null){
            throw ServiceExceptionUtil.exception(ErrorCodeConstants.COMMON_INFO_EXISTS, orderCode);
        }
        return order;
    }

    public TruckOrderDto factoryOrderDto(String orderCode) {
        TruckOrdersDO truckOrderByCode = getTruckOrderByCode(orderCode);
        TruckOrderDto truckOrderDto = new TruckOrderDto();
        truckOrderDto.setTruckOrdersDO(truckOrderByCode);

        return truckOrderDto;
    }

    @Transactional
    public TruckOrdersDO applyCancelOrder(String orderCode,String cancelReason) {
        LambdaQueryWrapperX<TruckOrdersDO> ordersWrapperX = new LambdaQueryWrapperX<>();
        ordersWrapperX.eq(TruckOrdersDO::getOrderCode, orderCode);
        TruckOrdersDO order = this.getOne(ordersWrapperX);
        if(order == null){
            throw ServiceExceptionUtil.exception(ErrorCodeConstants.COMMON_INFO_EXISTS, orderCode);
        }


        LambdaQueryWrapperX<TruckOrderCancelLogDO> cancelWrapper = new LambdaQueryWrapperX<>();
        cancelWrapper.eq(TruckOrderCancelLogDO::getOrderCode, orderCode);
        TruckOrderCancelLogDO cancelLog = truckOrderCancelLogService.getOne(cancelWrapper);
        if(cancelLog != null){
            throw ServiceExceptionUtil.exception(ErrorCodeConstants.BIZ_CANCEL_REPEAT, orderCode);
        }
        TruckOrderCancelLogDO orderCancelDO = new TruckOrderCancelLogDO();
        orderCancelDO.setOrderCode(orderCode);
        orderCancelDO.setOpType("cancel");
        orderCancelDO.setApprovalStatus(ApprovalTypeEnum.WAIT_APPROVAL.getValue());
        //系统取消
        orderCancelDO.setOlType(0);
        orderCancelDO.setCustomerCode(order.getCustomerCode());
        orderCancelDO.setSmCode(order.getProductCode());
        orderCancelDO.setAsCode(order.getSpCode());
        orderCancelDO.setOrderStatusFrom(order.getOrderStatus());
        orderCancelDO.setOrderStatusTo(OrderStatusEnum.CANCELLING.getValue());
        orderCancelDO.setOlComments(cancelReason);
        orderCancelDO.setUserId(SecurityFrameworkUtils.getLoginUserId());
        truckOrderCancelLogService.save(orderCancelDO);
        order.setOrderStatus(OrderStatusEnum.CANCELLING.getValue());
        this.updateById(order);

        //记录订单日志
        truckOrderLogService.addTruckOrderCacncelLog(order,orderCancelDO);
        return  order;
    }

    /**
     * 申请取消订单
     * todo： 取消通过后考虑是否需要回退费用？
     * @param approvalVO
     * @return
     */
    @Override
    @LogRecord(type = SYSTEM_ORDER_TYPE, subType = SYSTEM_ORDER_UPDATE_TYPE, bizNo = "{{#order.orderCode}}",
            success = SYSTEM_ORDER_CANCEL_APPROVE_SUCCESS)
    @Transactional
    public TruckOrdersDO approveCancelOrder(TruckOrderApprovalVO approvalVO) {
        String orderCode = approvalVO.getOrderCode();
        LambdaQueryWrapperX<TruckOrdersDO> ordersWrapperX = new LambdaQueryWrapperX<>();
        ordersWrapperX.eq(TruckOrdersDO::getOrderCode, orderCode);
        TruckOrdersDO order = this.getOne(ordersWrapperX);
        if(order == null){
            throw ServiceExceptionUtil.exception(ErrorCodeConstants.COMMON_INFO_EXISTS, orderCode);
        }
        LambdaQueryWrapperX<TruckOrderCancelLogDO> cancelWrapper = new LambdaQueryWrapperX<>();
        cancelWrapper.eq(TruckOrderCancelLogDO::getOrderCode, orderCode);
        TruckOrderCancelLogDO cancelLog = truckOrderCancelLogService.getOne(cancelWrapper);
        if(cancelLog == null){
            throw ServiceExceptionUtil.exception(ErrorCodeConstants.BIZ_CANCEL_NOT_EXIST, orderCode);
        }

        boolean locked = false;
        String lockName = RedisLockConstants.ORDER_UPDATE + approvalVO.getOrderCode();
        try {
            locked = lockManager.tryLock(lockName,10, 50);
            if(!locked){
                log.error("获取订单锁失败,{}", lockName);
                throw ServiceExceptionUtil.exception(ErrorCodeConstants.REQUEST_EXCEPTION, "get order sync lock failed,"+lockName);
            }

            cancelLog.setApprovalStatus(approvalVO.getApprovalStatus());
            cancelLog.setApprovalMsg(approvalVO.getApprovalReason());
            Integer approvalStatus = approvalVO.getApprovalStatus();
            if(approvalStatus.equals(ApprovalTypeEnum.PASS.getValue())) {
                //通过
                order.setOrderStatus(OrderStatusEnum.CANCELED.getValue());
                //退回费用
                orderFeeDetailService.deleteFeeByOrderCode(order);
            } else  {
                //其他都为不通过
                Integer orderStatusFrom = cancelLog.getOrderStatusFrom();
                order.setOrderStatus(orderStatusFrom);
            }
            this.saveOrUpdate(order);
            truckOrderCancelLogService.saveOrUpdate(cancelLog);

            return order;

        }catch (InterruptedException e){
            log.error("操作订单信息异常,订单号：{}, 错误信息：{}", approvalVO.getOrderCode(), e.getMessage());
            throw ServiceExceptionUtil.exception(ErrorCodeConstants.REQUEST_EXCEPTION, e.getMessage());
        }finally {
            if (locked) {
                lockManager.unlock(lockName);
            }
            LogRecordContext.putVariable("order", order);
        }
    }

    /**
     * 获取当日订单统计信息
     * @return
     */
    public OrderStatVO getOrderStat(){
        Boolean currentUserAdmin = userRoleService.isCurrentUserAdmin();
        String customerCode = null;
        if( !currentUserAdmin ) {
            // 非管理员只能查询自己账号下订单
            customerCode = SecurityFrameworkUtils.getLoginUser().getUsername();
        }

        OrderStatVO orderStatVO = new OrderStatVO();
        // 获取当天开始和结束时间
        LocalDateTime todayStart = LocalDate.now().atStartOfDay();
        LocalDateTime todayEnd = todayStart.plusDays(1);

        QueryWrapper<TruckOrdersDO> truckOrdersDOQueryWrapper = Wrappers.<TruckOrdersDO>query()
                .select("order_status, COUNT(*) AS count");
        if(customerCode !=null){
            truckOrdersDOQueryWrapper.eq("customer_code",customerCode);
        }
        truckOrdersDOQueryWrapper.between("create_time", todayStart, todayEnd)
                .groupBy("order_status");


        List<Map<String, Object>> maps = this.listMaps(truckOrdersDOQueryWrapper);
        Integer total = 0;
        Integer cancelNum = 0;
        Integer abnormalNum = 0;
        for (Map<String, Object> map : maps) {
            Long count = (Long)map.get("count");
            total = total + count.intValue();
            Integer orderStatus = (Integer)map.get("order_status");
            if(orderStatus.equals(OrderStatusEnum.CANCELED.getValue()) || orderStatus.equals(OrderStatusEnum.CANCELLING.getValue())){
                cancelNum = cancelNum + count.intValue();
            }
            if( orderStatus.equals(OrderStatusEnum.ABNORMAL_FORECAST.getValue()) ) {
                abnormalNum = abnormalNum+ count.intValue();
            }
        }
        orderStatVO.setTodayOrderCancel(cancelNum);
        orderStatVO.setTodayOrderCount(total);
        orderStatVO.setTodayOrderAbnormal(abnormalNum);


        List<Map<String, Object>> last30DaysOrderStats = this.baseMapper.getLast30DaysOrderStats(customerCode);
        Map<String,Long> mapValues = new HashMap<>();
        for (Map<String, Object> mapstat : last30DaysOrderStats) {
            String orderDate = String.valueOf(mapstat.get("order_date"));
            Long count = (Long)mapstat.get("order_count");
            mapValues.put(orderDate,count);
        }

        // 2. 创建完整30天日期列表
        Map<LocalDate, Map<String, Object>> resultMap = new LinkedHashMap<>();
        LocalDate today = LocalDate.now();

        // 初始化30天map，填充0值
        List<OrderNumVo> orderNumVos = new ArrayList<>();
        DateTimeFormatter dateFormat = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        // 格式化为 MM-dd
        DateTimeFormatter dayFormat = DateTimeFormatter.ofPattern("MM-dd");
        for (int i = 0; i < 30; i++) {
            LocalDate date = today.minusDays(29 - i);
            String dateTime = date.format(dateFormat);
            String dayTime = date.format(dayFormat);
            OrderNumVo orderNumVo = new OrderNumVo();
            orderNumVo.setDate(dateTime);
            orderNumVo.setDisplayDate(dayTime);
            if(mapValues.get(dateTime) == null){
                orderNumVo.setValue(0L);
            }else {
                orderNumVo.setValue(mapValues.get(dateTime));
            }
            orderNumVos.add(orderNumVo);
        }
        // 3. 合并实际统计数据
        orderStatVO.setOrderNumVoList(orderNumVos);
        return orderStatVO;
    }



}